#!/bin/bash

tidb_host='{{ params.tidb_host }}'
tidb_port='{{ params.tidb_port }}'
tidb_url='{{ params.tidb_url }}'
tidb_user='{{ params.tidb_user }}'
tidb_password='{{ params.tidb_password }}'

hive_table='{{ params.hive_table }}'
tidb_table='{{ params.tidb_table }}'
if_partitions='{{ params.if_partitions }}'
partition_keys='{{ params.partition_keys }}'
partition_values='{{ params.partition_values }}'
update_key='{{ params.update_key }}'
interval_dt='{{ params.interval_dt }}'
sqoop_maps='{{ params.sqoop_maps }}'
sqoop_execution_date='{{ execution_date | cst_ds }}'

start_date='{{ execution_date | cst_ds_nodash }}'



# 导入数据
export_to_tidb() {
	sqoop_shell="sqoop export \
	-Dsqoop.export.records.per.statement=100 \
	-Dsqoop.export.statements.per.transaction=10 \
	--connect                     ${tidb_url} \
	--username                    ${tidb_user} \
	--password                    ${tidb_password} \
	--table                       ${tidb_table#*.} \
	--hcatalog-database           ${hive_table%%.*} \
	--hcatalog-table              ${hive_table#*.} \
	--hcatalog-partition-keys ${partition_keys}  \
	--hcatalog-partition-values ${partition_values} \
	--update-key ${update_key} \
	--update-mode allowinsert  \
  --batch \
	-m ${sqoop_maps} "
  echo 'Sqoop Shell : ' ${sqoop_shell}
	eval ${sqoop_shell} && echo "Sqoop export  executed successfully~~~" || { echo "Sqoop export  executed failed!!!"; exit 1; }
}

main() {

export_to_tidb

}

main